<?php if(!defined('BASEPATH')) exit('No direct script allowed');

class mdl_dashboard extends CI_Model{
	
	function __construct()
	{
		parent::__construct();
	}
	
	function anggaran($year)
	{		$this->db->flush_cache();		$query="		select anggaran.parent,(SELECTsum(anggaran.jumlah) as jumlahFROManggaranINNER JOIN anggaran_post ON anggaran_post.id_anggaran = anggaran.id_anggaran)as bukan,(SELECTsum(anggaran.jumlah) as jumlahFROManggaranINNER JOIN anggaran_post ON anggaran_post.id_anggaran = anggaran.id_anggaranwhere anggaran.parent  like '%.0'  ) as semua,((SELECTsum(anggaran.jumlah) as jumlahFROManggaranINNER JOIN anggaran_post ON anggaran_post.id_anggaran = anggaran.id_anggaran)-(SELECTsum(anggaran.jumlah) as jumlahFROManggaranINNER JOIN anggaran_post ON anggaran_post.id_anggaran = anggaran.id_anggaranwhere anggaran.parent  like '%.0'  ) )as selisihfrom anggaranINNER JOIN anggaran_post ON anggaran_post.id_anggaran = anggaran.id_anggaranwhere   anggaran_post.tahun = 2022		";		$hasil = $this->db->query($query);		return $hasil;
	}
	function pendapatan($year)	{		$this->db->flush_cache();		$query="		SELECT			Sum(detail_jurnal.debet) AS jml_debet,			Sum(detail_jurnal.kredit) AS jml_kredit,			(sum(`detail_jurnal`.`debet`) - sum(`detail_jurnal`.`kredit`)) AS selisih 			FROM			detail_jurnal			INNER JOIN jurnal ON detail_jurnal.glid = jurnal.glid			where detail_jurnal.akunid like '4%'  and year(jurnal.tanggal) = $year		";		$hasil = $this->db->query($query);		return $hasil;	}		function pengeluaran($year)	{		$this->db->flush_cache();		$query="		SELECT			Sum(detail_jurnal.debet) AS jml_debet,			Sum(detail_jurnal.kredit) AS jml_kredit,			(sum(`detail_jurnal`.`debet`) - sum(`detail_jurnal`.`kredit`)) AS selisih 			FROM			detail_jurnal			INNER JOIN jurnal ON detail_jurnal.glid = jurnal.glid			where detail_jurnal.akunid like '5%'  and year(jurnal.tanggal) = $year		";		$hasil = $this->db->query($query);		return $hasil;	}		function piutang($year)	{		$this->db->flush_cache();		$query="SELECT sum(mcm.kredit) as piutangFROMmcmINNER JOIN penerimaan_kas ON penerimaan_kas.mcm = mcm.idINNER JOIN detail_penerimaan_kas ON penerimaan_kas.glid = detail_penerimaan_kas.glidINNER JOIN master_parawaba ON mcm.parawaba = master_parawaba.idWHERE penerimaan_kas.status_posting = 1 and mcm.parawaba = master_parawaba.id and year(mcm.tanggal) = $year";		$hasil = $this->db->query($query);		return $hasil;	}		
	
}